<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>Linux 命令- pwd | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>Linux 命令- pwd</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Linux命令/">Linux命令</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Linux中用 pwd 命令来查看”当前工作目录“的完整路径。 简单得说，每当你在终端进行操作时，你都会有一个当前工作目录。 在不太确定当前位置时，就会使用pwd来判定当前目录在文件系统内的确切位置。      </p>
<h2 id="1．命令格式："><a href="#1．命令格式：" class="headerlink" title="1．命令格式："></a>1．命令格式：</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">pwd</span> [选项]</div></pre></td></tr></table></figure>
<h2 id="2．命令功能："><a href="#2．命令功能：" class="headerlink" title="2．命令功能："></a>2．命令功能：</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;查看”当前工作目录“的完整路径</p>
<h2 id="3．常用参数："><a href="#3．常用参数：" class="headerlink" title="3．常用参数："></a>3．常用参数：</h2><ul>
<li>一般情况下不带任何参数 </li>
<li>如果目录是链接时：格式：pwd -P  显示出实际路径，而非使用连接（link）路径。</li>
</ul>
<h2 id="4．常用实例："><a href="#4．常用实例：" class="headerlink" title="4．常用实例："></a>4．常用实例：</h2><h3 id="实例1：用-pwd-命令查看默认工作目录的完整路径"><a href="#实例1：用-pwd-命令查看默认工作目录的完整路径" class="headerlink" title="实例1：用 pwd 命令查看默认工作目录的完整路径"></a>实例1：用 pwd 命令查看默认工作目录的完整路径</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">pwd</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># pwd</span></div><div class="line">/root</div><div class="line">[root@localhost ~]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h3 id="实例2：使用-pwd-命令查看指定文件夹"><a href="#实例2：使用-pwd-命令查看指定文件夹" class="headerlink" title="实例2：使用 pwd 命令查看指定文件夹"></a>实例2：使用 pwd 命令查看指定文件夹</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">pwd</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># cd /opt/soft/</span></div><div class="line">[root@localhost soft]<span class="comment"># pwd </span></div><div class="line">/opt/soft</div><div class="line">[root@localhost soft]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h3 id="实例3：目录连接链接时，pwd-P-显示出实际路径，而非使用连接（link）路径；pwd显示的是连接路径"><a href="#实例3：目录连接链接时，pwd-P-显示出实际路径，而非使用连接（link）路径；pwd显示的是连接路径" class="headerlink" title="实例3：目录连接链接时，pwd -P  显示出实际路径，而非使用连接（link）路径；pwd显示的是连接路径"></a>实例3：目录连接链接时，pwd -P  显示出实际路径，而非使用连接（link）路径；pwd显示的是连接路径</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">pwd</span> -P</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">[root@localhost soft]<span class="comment"># cd /etc/init.d </span></div><div class="line">[root@localhost init.d]<span class="comment"># pwd</span></div><div class="line">/etc/init.d</div><div class="line">[root@localhost init.d]<span class="comment"># pwd -P</span></div><div class="line">/etc/rc.d/init.d</div><div class="line">[root@localhost init.d]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h3 id="实例4：-bin-pwd"><a href="#实例4：-bin-pwd" class="headerlink" title="实例4：/bin/pwd"></a>实例4：/bin/pwd</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">/bin/<span class="built_in">pwd</span> [选项]</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;选项：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>-L 目录连接链接</code>时，输出连接路径</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>-P 输出物理路径</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">[root@localhost init.d]<span class="comment"># /bin/pwd </span></div><div class="line">/etc/rc.d/init.d</div><div class="line">[root@localhost init.d]<span class="comment"># /bin/pwd --help</span></div><div class="line">[root@localhost init.d]<span class="comment"># /bin/pwd -P</span></div><div class="line">/etc/rc.d/init.d</div><div class="line">[root@localhost init.d]<span class="comment"># /bin/pwd -L</span></div><div class="line">/etc/init.d</div><div class="line">[root@localhost init.d]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h3 id="实例5：当前目录被删除了，而pwd命令仍然显示那个目录"><a href="#实例5：当前目录被删除了，而pwd命令仍然显示那个目录" class="headerlink" title="实例5：当前目录被删除了，而pwd命令仍然显示那个目录"></a>实例5：当前目录被删除了，而pwd命令仍然显示那个目录</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">[root@localhost init.d]<span class="comment"># cd /opt/soft</span></div><div class="line">[root@localhost soft]<span class="comment"># mkdir removed</span></div><div class="line">[root@localhost soft]<span class="comment"># cd removed/</span></div><div class="line">[root@localhost removed]<span class="comment"># pwd</span></div><div class="line">/opt/soft/removed</div><div class="line">[root@localhost removed]<span class="comment"># rm ../removed -rf</span></div><div class="line">[root@localhost removed]<span class="comment"># pwd</span></div><div class="line">/opt/soft/removed</div><div class="line">[root@localhost removed]<span class="comment"># /bin/pwd</span></div><div class="line">/bin/<span class="built_in">pwd</span>: couldn<span class="string">'t find directory entry in “..” with matching i-node</span></div><div class="line"><span class="string">[root@localhost removed]# cd </span></div><div class="line"><span class="string">[root@localhost ~]# pwd</span></div><div class="line"><span class="string">/root</span></div><div class="line"><span class="string">[root@localhost ~]#</span></div></pre></td></tr></table></figure>
	

	
		<span class="different-posts"><a href="/2017/10/12/2. Linux 命令/4. Linux 命令-pwd/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
